import requests
import lxml.etree as le
import pandas as pd

url = 'https://www.runoob.com/html/html-tutorial.html'  # 对象网页地址
content = requests.get(url).content

class x(): #记录提取对象
    i = '//div[@class="left-column"]//div[@id="leftcolumn"]/a//text()' # 列表名称
    j = '//div[@class="left-column"]//div[@id="leftcolumn"]/a/@href' # 列表链接

contentx = le.HTML(content)

cols = contentx.xpath(x.i)
links = contentx.xpath(x.j)

col = []  # 创建DataFrame对象
link = []
for a in cols:
    col.append(a.strip())
for b in links:
    link.append('https://www.runoob.com' + b.strip())

col_link = pd.DataFrame(list(zip(col,link))) # 得到DataFrame对象
col_link.columns = ['title','url']  # 对列命名


writer = pd.ExcelWriter('RUNOOB_HTML_URL.xlsx')  # 写入Excel
col_link.to_excel(writer,sheet_name='url')
writer.save()